﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using ActivePalControls.ControlsData;

namespace ActivePalInterop.Data
{
    /// <summary>
    /// Convert enum to database char or string ojects and vice versa
    /// </summary>
    public class GenderConverter
    {
        /// <summary>
        /// Convert gender to database char
        /// </summary>
        /// <param name="gender">Human gender</param>
        /// <returns>database char</returns>
        public static char ToChar(Gender gender)
        {
            switch (gender)
            {
                case Gender.Unknown:
                    return 'u';
                case Gender.Male:
                    return 'm';
                case Gender.Female:
                    return 'f';
                default:
                    throw new ArgumentException("unknown type");
            }
        }

        /// <summary>
        /// Convert database char to gender 
        /// </summary>
        /// <param name="c">database char</param>
        /// <returns>Human gender</returns>
        public static Gender ToGender(char c)
        {            
            switch (c)
            {
                case 'u':
                    return Gender.Unknown;
                case 'm':
                    return Gender.Male;
                case 'f':
                    return Gender.Female;
                default:
                    throw new ArgumentException("unknown type");
            }
        }

        /// <summary>
        /// Convert string to gender 
        /// </summary>
        /// <param name="s">Respective string representation of gender</param>
        /// <returns>Human gender</returns>
        public static Gender ToGender(string s)
        {
            char firstLetter = Convert.ToChar(s.Substring(0, 1).ToLower());
            return ToGender(firstLetter);            
        }

        /// <summary>
        /// Convert gender to string 
        /// </summary>
        /// <param name="gender">Human gender</param>
        /// <returns>Respective string representation of gender</returns>
        public static string ToString(Gender gender)
        {
            switch (gender)
            {
                case Gender.Unknown:
                    return "Unknown";
                case Gender.Male:
                    return "Male";
                case Gender.Female:
                    return "Female";
                default:
                    throw new ArgumentException("unknown type");
            }
        }
    }
}
